//
//  CZBaseTableViewController.swift
//  sinaWeiboswift
//
//  Created by 段文杰 on 16/4/9.
//  Copyright © 2016年 段文杰. All rights reserved.
//

import UIKit
import SVProgressHUD

class CZBaseTableViewController: UITableViewController {

    
//    var  userLogin : Bool = false
    
    var userLogin = CZUseraccountViewModel.sharInatance.userLogin
    
    
    override func loadView() {
        userLogin ? super.loadView() : setupView()
    }
    
    
    
    func setupView () {
        
        let view = UIView()
        view.backgroundColor = UIColor.init(red: ( CGFloat(arc4random_uniform(256)) / 255.0), green: ( CGFloat(arc4random_uniform(256)) / 255.0), blue: ( CGFloat(arc4random_uniform(256)) / 255.0), alpha: 1.0)
        
        //根据vc类型显示不同的数据
        self.view = visitorView
        
        if self .isKindOfClass(CZHomeTableViewController) {
        visitorView.setrotation()
        }
        
        if self .isKindOfClass(CZmessageTableViewController) {
        visitorView.setvisitor("你把叫什么名字,牛逼么", imageName: "visitordiscover_image_message")
        }
        if self .isKindOfClass(CZDiscoverTableViewController) {
            visitorView.setvisitor("你把叫什么名字,牛逼么,发财了么", imageName: "visitordiscover_image_message")
        }
        if self .isKindOfClass(CZProfileTableViewController) {
            visitorView.setvisitor("你把叫什么名字,牛逼么,好玩吗,你把是咯刚", imageName: "visitordiscover_image_profile")
        }

        
        
        
    }
   
    override func viewDidLoad() {
        super.viewDidLoad()
 
        //闭包实现传值
        visitorView.coulouse1 = {
//        print("visitorViewBtn点击了注册")
        }
        visitorView.coulouse2 = {
//            print("visitorViewBtn点击了登陆")

        }
        
        //设置代理
        visitorView.delegate=self
        
    // MARK: - ******************* 导航栏按钮的设置 ********************
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target:self , action: #selector(CZBaseTableViewController.registBtnDidClick))
        self.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName:(UIColor.init(red: ( CGFloat(arc4random_uniform(256)) / 255.0), green: ( CGFloat(arc4random_uniform(256)) / 255.0), blue: ( CGFloat(arc4random_uniform(256)) / 255.0), alpha: 1.0))], forState: .Normal)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target:self , action: #selector(CZBaseTableViewController.loginBtnDidClick))
        self.navigationItem.rightBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName:(UIColor.init(red: ( CGFloat(arc4random_uniform(256)) / 255.0), green: ( CGFloat(arc4random_uniform(256)) / 255.0), blue: ( CGFloat(arc4random_uniform(256)) / 255.0), alpha: 1.0))], forState: .Normal)
    }
    
    lazy var visitorView: CZvisitorView = CZvisitorView()//懒加载一个view

}

extension CZBaseTableViewController : CZvisitorViewDelegate {
    @objc  func registBtnDidClick () {
        print("导航注册点击了")
    }
    @objc  func loginBtnDidClick () {
        print("导航登陆点击了")
        let oauthVC = CZOauthViewController()
        
        let nav = UINavigationController(rootViewController: oauthVC)
       
        self.presentViewController(nav, animated: true, completion: nil)
        
        
        
    }
    
    
}
